package cn.tedu.shoot;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @author JokerQiu
 * @desc 飞行物
 * @date 2021/12/05
 */
public abstract class FlyingObject {
    protected int width;
    protected int height;
    protected int x;
    protected int y;

    /**
     * 飞行物的状态
     */
    public static final int LIFE = 0;
    public static final int DEAD = 1;
    public static final int REMOVE = 2;
    protected int state = LIFE;

    /**
     * 行为
     */
    public abstract void step();

    public abstract BufferedImage getImage();

    public void paint(Graphics g){
        g.drawImage(getImage(),x,y,null);
    }

    public boolean isLife(){
        return state==LIFE;
    }

    public boolean isDead(){
        return state==DEAD;
    }

    public boolean isRemove(){
        return state==REMOVE;
    }

    public void goDead(){
        state = DEAD;
    }

    public boolean hit(FlyingObject other){
        int x1 = this.x-other.width;
        int x2 = this.x+this.width;
        int y1 = this.y-other.height;
        int y2 = this.y+this.height;
        int x = other.x;
        int y = other.y;

        return x>=x1 && x<=x2 && y>=y1 && y<=y2;
    }

    public abstract boolean outOfBounds();
}
